<?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;

class ArticleController extends BaseController {
    public function index(){

         //获取文章
        $id=I('get.id');
        $Article =M('Article');
        $map['status']=1;
        $map['classify']=$id;
        $order='createtime desc';
        $count  =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map)->count();
        $Page = new \Think\Page1($count,5);
        $show = $Page->show();
           
        $art =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
 
        $list =$art[0]['name']; 
        
        //获取推荐文章
        
        $map_recom['is_recom']=1;
        $map_recom['status']=1;
        $map_recom['classify']=$id;
        $art_recom =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map_recom)->order($order)->limit(0,6)->select();
        
        $Ad =M('Picture');
        //获取广告图片
        $map_ad['state']=1;
        $map_ad['classify']=2;
        $ad =$Ad->where($map_ad)->limit(0,2)->select();     
        $ad1=$ad[0];
        $ad2=$ad[1];

        $this->assign('list',$list);
        $this->assign('page',$show);
        $this->assign('article',$art); 
        $this->assign('article_recom',$art_recom);
        $this->assign('ad1',$ad1);
        $this->assign('ad2',$ad2);
        $this->display('index');
    }
    
    
   public function  lst(){
       //获取文章
        $id=I('get.id');
        $Article =M('Article');
        $map['status']=1;
        $map['classify']=$id;
        $order ='createtime desc';

        $count  =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map)->count();
        $Page = new \Think\Page1($count,6);
        $show = $Page->show();

        $art =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
        $list =$art[0]['name'];

        //获取推荐文章
        
        $map_recom['is_recom']=1;
        $map_recom['status']=1;
        $map_recom['classify']=$id;
        $art_recom =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map_recom)->order($order)->limit(0,4)->select();
        
        //获取轮播的文章
        $map['is_banner']=1;
        $map_recom['status']=1;
        $map_recom['classify']=$id;
        $art_banner =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map_recom)->order($order)->limit(0,4)->select();
        
        
        $this->assign('list',$list);
        $this->assign('page',$show);
        $this->assign('article',$art);
        $this->assign('article_recom',$art_recom);
        $this->assign('article_banner',$art_banner);
        $this->display('lst');
        
        
   }
   
   
   public function detail(){
       
       $id=I('get.id');
       $Article =M('Article');

       $map['id']=$id;
       $art =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map)->find();      
       $list =$art['name'];

       
       
       //获取精品导读
       $map_recom['index_recom']=1;
       $map_recom['status']=1;
       $order='createtime desc';
       $index_recom =$Article->join('__ARTICLE_CAT__ ON __ARTICLE__.classify = __ARTICLE_CAT__.cid','left')->where($map_recom)->order($order)->limit(0,5)->select();
       
       
        $Ad =M('Picture');
        //获取广告图片
        $map_ad['state']=1;
        $map_ad['classify']=3;
        $ad =$Ad->where($map_ad)->limit(0,2)->select();
        $ad1=$ad[0];
        $ad2=$ad[1];

       $this->assign('article_recom',$index_recom);
       $this->assign('article',$art);
       $this->assign('list',$list);
       $this->assign('ad1',$ad1);
       $this->assign('ad2',$ad2);
       $this->display('detail');
   }
   
   
   
   
   
   
   
   
   
   
   
   
}